package com.chief.openfeign.web.filter;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Component
@WebFilter(filterName = "test-config-filter", urlPatterns = "/**")
//表示如果有多个拦截器的话就是设置这个拦截器的运行等级，数字越小，越先执行
@Order(1)
public class TestConfigFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("TestConfigFilter init");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        System.out.println("TestConfigFilter doFilter path is " + httpServletRequest.getServletPath());
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        System.out.println("TestConfigFilter destroy");
    }
}
